﻿using System;
using System.Web;
using System.Net.Mail;
using System.Web.UI;
using SimplePMT.Data;
using SimplePMT.Control;
using System.Text;
using System.Collections.Generic;
using Castle.ActiveRecord;
using NHibernate.Expression;
using SimplePMT.Components;

namespace SimplePMT
{
    public partial class ReportProjectStatus : Components.BasePage
    {
        public string StartDate = string.Empty;
        public string EndDate = string.Empty;
        public string onLoadReport = string.Empty;
        public string[] projectList;

        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ReportProjectStatus), this.Page);
            ValidateSession();

            if (Request.QueryString["start"] != null && Request.QueryString["end"] != null)
            {
                StartDate = Request.QueryString["start"];
                EndDate = Request.QueryString["end"];
            }
            if (StartDate.Length.Equals(0))
            {
                StartDate = DateTime.Now.AddDays(-7).ToShortDateString();
                EndDate = DateTime.Now.ToShortDateString();
            }
            projectList = BuildProjectList();
            onLoadReport = GetStatusReport(StartDate, EndDate, 0);
        }
        private string[] BuildProjectList()
        {
            TaskContainer[] containerItems = TaskContainer.FindAll(Expression.Eq("IsAWISHProject", true));
            string[] containerList = new string[containerItems.Length + 1];
            using (new SessionScope())
            {
                int i = 1;
                containerList[0] = "0=SELECT PROJECT";
                foreach (TaskContainer container in containerItems)
                {
                    containerList[i] = container.ID + "=" + container.Label;
                    i++;
                }
            }
            return containerList;
        }
        [AjaxPro.AjaxMethod()]
        public string GetStatusReport(string fromDate, string toDate, int taskContainerId)
        {
            Control.ReportProjectStatusControl view = this.LoadControl("./Control/ReportProjectStatusControl.ascx") as Control.ReportProjectStatusControl;
            view.FromDate = fromDate;
            view.ToDate = toDate;
            view.TaskContainerID = taskContainerId;
            return view.ToString();
        }

    }
}
